package com.example.nettyrpcdemo.rpchandler;

import com.example.nettyrpcdemo.core.GameRpcMsgContext;
import com.example.nettyrpcdemo.core.RpcMsgReceiver;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import msg.MsgCross;
import org.springframework.stereotype.Controller;

@Slf4j
@Controller
public class GameRpcHandler {

    @RpcMsgReceiver(MsgCross.TestMessage.class)
    public void testMessage(GameRpcMsgContext context) {
        MsgCross.TestMessage msg = context.getMsg();
        log.info("testMessage {}", msg.getTag());
    }

    @RpcMsgReceiver(MsgCross.TestAsk.class)
    public void testAsk(GameRpcMsgContext context) {
        MsgCross.TestAsk msg = context.getMsg();
        log.info("testAsk {}", msg.getTag());

        MsgCross.TestAnswer.Builder answer = MsgCross.TestAnswer.newBuilder();
        answer.setTag("answer-" + msg.getTag());
        context.sendAnswerMsg(answer.build());
    }
}
